package com.agrm.model.common.dtos;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

@JsonIgnoreProperties("handler")
@Getter
@Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
public abstract class TreeEntity<T extends TreeEntity<T, ID>, ID extends Serializable> extends BaseModel {
    @EqualsAndHashCode.Include
    private ID id;//节点编号
    private ID parentId;//父节点编号

    //一对一关联查询（是否进行关联查询，取决于实际需要）
    //注解@JsonBackReference表示序列化时忽略（防止出现序列化死循环），反序列化时应用
    //由于jackson不进行序列化，故不会触发延迟加载
    @JsonBackReference
    private T parent;

    //不进行关联查询
    //注解@JsonManagedReference表示参与序列化（前提是children非空）
    @JsonManagedReference
    private List<T> children;
}
